//
//  ZLMeiTuanRefreshControl.swift
//  刷新控件
//
//  Created by zhanglongtao on 17/1/4.
//  Copyright © 2017年 hanju001. All rights reserved.
//

import UIKit

class ZLMeiTuanRefreshControl: ZLRefreshView {

    
    
    @IBOutlet weak var buildIconView: UIImageView!
    
    @IBOutlet weak var earthView: UIImageView!
    
    @IBOutlet weak var kangarooView: UIImageView!
    
    override var parentViewHeight: CGFloat {
        
        didSet{
            
            print("父视图高度\(parentViewHeight)")
            //23- 126
            if parentViewHeight < 23
            {
                return
            }
            var scale: CGFloat
            if parentViewHeight > 126{
                scale = 1
            }else
            {
                scale = 1 - (126 - parentViewHeight) / (126 - 23)
            }
            
            kangarooView.transform = CGAffineTransform(scaleX: scale, y: scale)
            
        }
        
    }
    
    override func awakeFromNib() {
        
        //房子
        let bImage = #imageLiteral(resourceName: "icon_building_loading_1")
        let bImage2 = #imageLiteral(resourceName: "icon_building_loading_2")
        
        buildIconView.image = UIImage.animatedImage(with: [bImage, bImage2], duration: 0.5)
        //地球
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = -2 * M_PI
        anim.repeatCount = MAXFLOAT
        anim.duration = 3
        anim.isRemovedOnCompletion = false
        earthView.layer.add(anim, forKey: nil)
        //袋鼠
        let kImage = #imageLiteral(resourceName: "icon_small_kangaroo_loading_1")
        let kImage2 = #imageLiteral(resourceName: "icon_small_kangaroo_loading_2")
        
        kangarooView.image = UIImage.animatedImage(with: [kImage, kImage2], duration: 0.5)
        
        kangarooView.transform = CGAffineTransform(scaleX: 0.2, y: 0.3)
        kangarooView.layer.anchorPoint = CGPoint(x: 0.5, y: 1)
        
        //需要在设置frame或者center
        let x = self.bounds.width * 0.5
        let y = self.bounds.height - 23
        kangarooView.center = CGPoint(x: x, y: y)
        
    }

}
